<template>
	<view>
		<uni-nav-bar :fixed="true" left-icon="back" title="我的收货地址" @clickLeft="leftBack" background-color="#318cff" color="#fff"></uni-nav-bar>
		<view class="dfj-overflow-hide">
			<block v-for="(item,index) in list">
				<view class="dfj-bg-white dfj-mg-lr-20 dfj-mg-t-20 dfj-bd-radius-20 dfj-overflow-hide dfj-pd-tb-20 dfj-pd-lr-30" :key="index">
					<view class="dfj-t-333 dfj-mg-b-20" @click="setAddress(item)">
						<text class="dfj-f-30">{{ item.userName }}</text><text class="dfj-f-26 dfj-mg-l-40">{{ item.mobilePhone }}</text>
					</view>
					<view class="dfj-mg-t-5 dfj-flex dfj-t-999">
						<view class="dfj-flex-1 dfj-mg-r-20" @click="setAddress(item)">
							<text v-if="item.isDefault" class="address-default">默认</text>{{ item.addressProvince }}{{ item.addressCounty }}{{ item.addressCity }}{{ item.address }}
						</view>
						<view class="" @click="toEdit(item)"><text class="dfj-f-30">编辑</text></view>
					</view>
				</view>
			</block>
		</view>
		
		<navigator url="/pages/home/address-add" hover-class="navigator-hover" class="dfj-mg-lr-20 dfj-pd-t-50 dfj-mg-t-50">
			<button size="mini" class="address-btn"><text class="dfj-icon icon-jia dfj-mg-r-30"></text>新增收货地址</button>
		</navigator>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				set: false
			}
		},
		onLoad(options) {
			console.log(options)
			if(options && options.set){
				this.set = options.set;
			}
		},
		onShow() {
			this.getList()
		},
		methods:{
			leftBack() {
				uni.navigateBack();
			},
			getList(){
				this.$http({
					url: '/userOpt/getReceivingAddressList'
				}).then(res=>{
					this.list = res.data;
				})
			},
			toEdit(item) {
				sessionStorage.setItem('editAddress', JSON.stringify(item))
				uni.navigateTo({
					url: '/pages/home/address-edit'
				})
			},
			setAddress(item){
				if(this.set != 'true'){
					sessionStorage.setItem('setAddress', JSON.stringify(item));
					uni.navigateBack()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.address-default{
		color: #318CFF;
		background-color: #eee;
		border-width: 1rpx;
		border-style: solid;
		border-color: #eee;
		display: inline-block;
		padding: 0 20rpx;
		margin-right: 20rpx;
	}
	.address-btn{
		background: #318CFF;
		width: 100%;
		color: #fff;
	}
</style>
